<template>
  <div class="content">
    <div class="action-box">
      <router-link to="/address_add">
        <img src="~assets/img/mall/icon_add.png">
        添加新地址
      </router-link>
    </div>
    <ul class="address-list">
      <li class="address-item" v-for="(item,index) in list" :key="index" @click="setAddress(item)">
        <div class="address-info">
          <p><span>{{item.receiver}}</span><span>{{item.phone}}</span></p>
          <p>{{item.area +　item.address}}</p>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import { apiPost } from 'src/common/api.js'
export default {
  name:'adress-select',
  data() {
    return {
      list:[]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      apiPost('addresses',{}).then((res) => {
        if (res.status === 0) {
          this.list = res.data
        } else {
          console.log(res.msg)
        }
      })
    },
    setAddress(data){
      this.$router.push({
          path: "/order_check",
          query: { 
            goods_id: this.$route.params.id,
            address_id: data.id
          }
        });
    }
  }
}
</script>
<style lang="scss" scoped>
  .action-box{
    border-bottom: 1px solid #d2d2d2;
    a{
      display: block;
      height: 55px;
      line-height: 55px;
      font-size: 14px;
      color: #333;
      text-align: center;
      background: #fff;
      img{
        margin-right: .5em;
        width: 25px;
        height: 25px;
        object-fit: contain;
      }
    }
  }
  .address-list{
    padding: 10px 0;
    .address-item{
      margin-bottom: 10px;
      .address-info{
        margin-bottom: 10px;
        padding: 15px;
        background: #fff;
        border-bottom: 1px solid #d2d2d2;
        p{
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    }
  }
</style>


